import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_tutorial/app/modules/state/workers/counter_controller.dart';

class WorkersPage extends GetView {

  @override
  Widget build(BuildContext context) {
    final c = Get.put(CounterController());

    return Scaffold(
      appBar: AppBar(
        title: Text('WorkersPage'),
        centerTitle: true,
      ),

      body: SafeArea(
        child: ListView(
          children: [
            Text(
              '- Workers 其实就是一些钩子函数\n- 必须在开始时，声明 Workers',
              style: Theme.of(context).textTheme.headline5
            ),
            Divider(),

            Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                ElevatedButton(
                  onPressed: () {
                    c.decrement();
                  }, 
                  child: Icon(Icons.remove)
                ),
                Obx(() => Text(
                  c.count.toString(),
                  style: Theme.of(context).textTheme.headline5
                )),

                ElevatedButton(
                  onPressed: () {
                    c.increment();
                  }, 
                  child: Icon(Icons.add)
                )
              ],
            ),
            Obx(() => Text('页码：'+c.page.toString())),
            ElevatedButton(
              onPressed: (){
                c.loadMore();
              }, 
              child: Text('下一页')
            )
          ]
        )
      )
    );
  }
}